package com.foreknow.demo27;

/**
 * 窗口类（线程）
 */
public class TicketThread implements Runnable {
    private Ticket t;
    private String name;

    public TicketThread(String name,Ticket t){
        this.name = name;
        this.t = t;
    }
    @Override
    public void run() {
        while (t.count>0){
            sell();
        }
    }

    public void sell() {
        //同步锁
        synchronized (t){
            if(t.count>0){
                System.out.println("NO."+t.count+"车票被"+name+"售出");
                t.count--;
            }
        }

    }
}
